<?php
/**
 * Created by 上海风车教育科技有限公司.
 * User: 刘红伟
 * Date: 15-11-26
 * Email: 454303753@qq.com
 * File:wechattemplate.php
 */
    class wechattemplate{
        const MSG_TYPE   = 1;
        private  $tpl;
        public function __construct($type=self::MSG_TYPE){
            switch($type){
                case 'test':
                    $this->_text();
                    break;
                case 'image':
                    $this->_image();
                    break;
                case 'voice':
                    $this->_voice();
                    break;
                case 'video':
                    $this->_video();
                    break;
                case 'music':
                    $this->_music();
                    break;
                case 'news':
                    $this->_news();
                    break;
                default:
                    $this->_text();
            }
        }
        private function _text(){
            $this->tpl="<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[text]]></MsgType>
                <Content><![CDATA[%s]]></Content>
            </xml>";
        }
       private function _image(){
           $this->tpl="<xml>
                    <ToUserName><![CDATA[%s]]></ToUserName>
                    <FromUserName><![CDATA[%s]]></FromUserName>
                    <CreateTime>%s</CreateTime>
                    <MsgType><![CDATA[image]]></MsgType>
                    <Image>
                    <MediaId><![CDATA[%s]]></MediaId>
                    </Image>
                </xml>";
       }
        private function _voice(){
            $this->tpl="
            <xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[voice]]></MsgType>
                <Voice>
                <MediaId><![CDATA[%s]]></MediaId>
                </Voice>
            </xml>
            ";
        }
        private function _video(){
            $this->tpl="
            <xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[video]]></MsgType>
                <Video>
                <MediaId><![CDATA[%s]]></MediaId>
                <Title><![CDATA[%s]]></Title>
                <Description><![CDATA[%s]]></Description>
                </Video>
            </xml>
            ";
        }

        private function _music(){
            $this->tpl="
            <xml>
                    <ToUserName><![CDATA[%s]]></ToUserName>
                    <FromUserName><![CDATA[%s]]></FromUserName>
                    <CreateTime>%s</CreateTime>
                    <MsgType><![CDATA[music]]></MsgType>
                    <Music>
                    <Title><![CDATA[%s]]></Title>
                    <Description><![CDATA[%s]]></Description>
                    <MusicUrl><![CDATA[%s]]></MusicUrl>
                    <HQMusicUrl><![CDATA[%s]]></HQMusicUrl>
                    <ThumbMediaId><![CDATA[%s]]></ThumbMediaId>
                    </Music>
            </xml>
            ";
        }

        private function _news(){
            $this->tpl="
            <xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[news]]></MsgType>
                <ArticleCount>1</ArticleCount>
                <Articles>
                <item>
                <Title><![CDATA[%s]]></Title>
                <Description><![CDATA[%s]]></Description>
                <PicUrl><![CDATA[%s]]></PicUrl>
                <Url><![CDATA[%s]]></Url>
                </item>

                </Articles>
            </xml>
            ";
        }



        public function getTpl(){
            return $this->tpl;
        }


    }